<?php
	include("../Includes/FusionCharts.php");
	include("../Includes/FusionCharts_Gen.php");
	include("../Includes/DBConn.php");
?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> 
<html xmlns="http://www.w3.org/1999/xhtml">
	<HEAD>
		<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
		<title>UPLB DV</title>
		
		<script language="Javascript" src="../js/FusionCharts.js"></script>
		<script type="text/javascript" src="../fancybox/jquery.min.js"></script>
		<script type="text/javascript" src="../fancybox/jquery.mousewheel-3.0.4.pack.js"></script>
		<script type="text/javascript" src="../fancybox/jquery.fancybox-1.3.4.pack.js"></script>
		<script type="text/javascript">

		$(document).ready(function() {
			$("a#example1").fancybox();

			$("a#example2").fancybox({
				'overlayShow'	: false,
				'transitionIn'	: 'elastic',
				'transitionOut'	: 'elastic'
			});

			$("a#example3").fancybox({
				'transitionIn'	: 'none',
				'transitionOut'	: 'none'	
			});

			$("a#example4").fancybox({
				'opacity'		: true,
				'overlayShow'	: false,
				'transitionIn'	: 'elastic',
				'transitionOut'	: 'none'
			});

			$("a#example5").fancybox();

			$("a#example6").fancybox({
				'titlePosition'		: 'outside',
				'overlayColor'		: '#000',
				'overlayOpacity'	: 0.9
			});

			$("a#example7").fancybox({
				'titlePosition'	: 'inside'
			});

			$("a#example8").fancybox({
				'titlePosition'	: 'over'
			});

			$("a[rel=example_group]").fancybox({
				'transitionIn'		: 'none',
				'transitionOut'		: 'none',
				'titlePosition' 	: 'over',
				'titleFormat'		: function(title, currentArray, currentIndex, currentOpts) {
				return '<span id="fancybox-title-over">Image ' + (currentIndex + 1) + ' / ' + currentArray.length + (title.length ? ' &nbsp; ' + title : '') + '</span>';
			}
		});

			$("#various1").fancybox({
					'titlePosition'		: 'inside',
					'transitionIn'		: 'none',
					'transitionOut'		: 'none'
			});

			$("#various2").fancybox();

			$("#various3").fancybox({
					'width'				: '75%',
					'height'			: '75%',
					'autoScale'			: false,
					'transitionIn'		: 'elastic',
					'transitionOut'		: 'elastic',
					'type'				: 'iframe'
			});

			$("#various4").fancybox({
					'padding'			: 0,
					'autoScale'			: false,
					'transitionIn'		: 'none',
					'transitionOut'		: 'none'
			});

		});

	</script>

		<link rel="stylesheet" href="../fancybox/jquery.fancybox-1.3.4.css" type="text/css" media="screen" />

	</HEAD>

	<BODY bgcolor="white">
	<CENTER>
			<?php
				$subject = $_GET['subject'];
				//echo $subject;
				if($subject=="default"){
					$snfirst = 2007;
					$snlast = 36018;
					$yearfirst = 2007;
					$yearlast = 2008;
					$semester = 1;
					$graph = 'Column3D';
				}
				else{
					$snfirst = $_POST['sn_first'];
					$snlast = $_POST['sn_last'];
					$yearfirst = $_POST['year_first'];
					$yearlast = $_POST['year_last'];
					$yearfirst2 = $_POST['year_first2'];
					$yearlast2 = $_POST['year_last2'];
					$semester = $_POST['semester'];
					$semester2 = $_POST['semester2'];
					$graph = 'Column3D';
					
					
				}
				
				$snnumber = $snfirst.$snlast;
				$studentnumber = $snfirst."-".$snlast;
				$ayear = $yearfirst."-".$yearlast;
				$ayear2 = $yearfirst2."-".$yearlast2;		

				$link = connectToDB();
				$strQuery0 = "select * from tempStudents where studentNumber='$snnumber'";
				$result0 = mysql_query($strQuery0) or die(mysql_error());
				$ors = mysql_fetch_array($result0);
				$fullname = $ors['firstName']." ".$ors['lastName'];
				
				if($semester == 1){
					$semname ="First";
				}
				else if($semester == 2){
					$semname = "Second";
				}
				else if($semester == 3){
					$semname = "Third";
				}
				
								
				if($semester2 == 1){
					$semname2 ="First";
				}
				else if($semester2 == 2){
					$semname2 = "Second";
				}
				else if($semester2 == 3){
					$semname2 = "Third";
				}
				
				//if second range is empty
				if(($yearfirst2 == ""  ) && ($yearlast2 == "")){		
					$schoolyear = $semname." Semester ".$ayear;
					$yAxis = "grade";
					
					$FC = new FusionCharts($graph,"850","430");
					$FC->setSwfPath("../FusionCharts/");
					$strParam="caption=$fullname; subcaption=$schoolyear; xAxisName=Subjects; yAxisName=Grades; formatNumberScale=0; decimalPrecision=2; yaxisminvalue=0; yaxismaxvalue=9; numdivlines=9";
					$FC->setChartParams($strParam);
					$link = connectToDB();
					$strQuery = "select grade, courseCode from tempSubjects where studentNumber="."$snnumber"." and academicYear="."$yearfirst"." and semester="."$semester";
					
					if($snnumber!=""){
						$result = mysql_query($strQuery) or die(mysql_error());
					}
					
					if ($result) 
					{
						$FC->addDataFromDatabase($result, $yAxis, "courseCode");
					}

					mysql_close($link);
					$FC->renderChart();
				
				}
				
				else{
					$schoolyear = $semname." Semester ".$ayear." to ".$semname2." Semester ".$ayear2;
					$yAxis = "grade";
					
					$FC = new FusionCharts($graph,"850","430");
					$FC->setSwfPath("../FusionCharts/");
					$strParam="caption=$fullname; subcaption=$schoolyear; xAxisName=Subjects; yAxisName=Grades; formatNumberScale=0; decimalPrecision=2; yaxisminvalue=0; yaxismaxvalue=9; numdivlines=9";
					$FC->setChartParams($strParam);
					$link = connectToDB();
								
					$aytemp = $yearfirst;
					$semtemp = $semester;
					$count = 0;
					$count2 = 0;
					$counter = 0;
					while($aytemp <= $yearfirst2){
						if(($aytemp == $yearfirst2) && ($semtemp > $semester2)){
							break;
						}
						else{
							$strQuery = "select grade, courseCode from tempSubjects where studentNumber="."$snnumber"." and academicYear="."$aytemp"." and semester="."$semtemp";
							$result = mysql_query($strQuery) or die(mysql_error());
						
							$aytemp2 = $aytemp + 1;
							$year = $semtemp." Sem ".$aytemp."=".$aytemp2;
							$FC->addCategory($year);
							while($ors = mysql_fetch_array($result)) {
								$temp[$count][$count2] = $ors['grade'];
								$count2++;			
								$FC->addDataFromDatabase($result, "grade", "courseCode");
					
							}
							//echo $year;
						}
						if($count2 > $counter){
							$counter=$count2;
						}
						
						//echo "<br />";
						if($semtemp==3){
							$aytemp = $aytemp + 1;
							$semtemp = 1;
						}
						else{
							$semtemp++;							
						}
						$count++;
						$count2=0;
					}
					/*
					for($i=0; $i<10; $i++){
						for($j=0; $j<10; $j++){
							echo $temp[$i][$j]." ";
						}
						echo "<br>";
					}
					*/
					
					mysql_close($link);
					$FC->renderChart();
									
				}
				
				
			?>
	</CENTER>
	</BODY>
</HTML>